import java.util.Arrays;
import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: liangyuanzhang
 * Date: 2025-3-02
 * Time: 15:46
 */
class Student{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test {

    //验证回文串
    public boolean isPalindrome(String s){
        s = s.toLowerCase();
        int left = 0;
        int right = s.length()-1;
        while (left < right){
            while (left < right && !isNumberAndCharacter(s.charAt(left))){
                left++;
            }
            while (left < right && !isNumberAndCharacter(s.charAt(right))){
                right--;
            }
            if(s.charAt(left) == s.charAt(right)){
                left++;
                right--;
            }else {
                return false;
            }
        }
        return true;
    }

    private boolean isNumberAndCharacter(char ch){
        if (Character.isDigit(ch) || Character.isLetter(ch)){
            return true;
        }
        return false;
    }



    public int firstUniqChar(String s) {
        int[] count = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            count[ch - 'a'] ++;
        }
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(count[ch - 'a'] == 1){
                return i;
            }
        }
        return -1;
    }
    public static void main15(String[] args) {
        String s = "   abc d e f g   ";
        System.out.println(s);

        String s2 = s.trim();//只会去除 左右两边的空格
        System.out.println(s2);
    }
    public static void main14(String[] args) {
        String s = "abcdef";
        String s2 = s.substring(2);
        System.out.println(s2);
    }
    public static void main13(String[] args) {
        String s = "abc\\def";
        //System.out.println(s);
        String[] strings = s.split("\\\\");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }

    }
    public static void main12(String[] args) {
        //”name=zhangsan&age=10“
        String s = "name=zhangsan&age=10";
        String[] strings = s.split("&");// 字符串的拆分
        for (int i = 0; i < strings.length; i++) {// 拆分后 是数组
            //strings[i] = name=zhangsan
            //strings[i] = age=10
            //System.out.println(strings[i]);
            String[] ss = strings[i].split("=");
            for (int j = 0; j < ss.length; j++) {
                System.out.println(ss[j]);
            }
        }
    }
    public static void main11(String[] args) {
        String s = "ababcabcd";
        System.out.println(s.replace('a', 'k'));
    }
    public static void main10(String[] args) {
        String s = "hello";
        char[] array = s.toCharArray();
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }

        String s2 = String.format("%d-%d-%d",2019,9,14);
        System.out.println(s2);
    }
    public static void main9(String[] args) {
        String s = "hello";// 只要是涉及到String类型的转变 都不是在原有的字符串上进行修改
        String s2 = s.toUpperCase();
        System.out.println(s2);

        String s3 = "HELLO";
        System.out.println(s3.toLowerCase());
    }
    public static void main8(String[] args) {
        String s1 = String.valueOf(1234);
        String s2 = String.valueOf(12.34);
        String s3 = String.valueOf(true);
        //都属于字符串
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);

        String s4 = String.valueOf(new Student("元章",13));// 序列化(把对象 变成字符串)
        System.out.println(s4);

        int data1 = Integer.parseInt("1234");
        double data2 = Double.parseDouble("12.34");
        System.out.println(data1+1);
        System.out.println(data2);

    }
    public static void main7(String[] args) {
        String s = "ababcabcd";

        int index = s.lastIndexOf('a',6);// 从后往前找下标
        System.out.println(index);
    }
    public static void main6(String[] args) {
        String s = "hello";

       int index =  s.indexOf('l');// 找到对应字符的下标(默认从0位置开始找)
        System.out.println(index);

        index =  s.indexOf('l',3);// 找到对应字符的下标，3下标的'l'
        System.out.println(index);

        index = s.indexOf("ll");// 找到对应字符的下标(默认从0位置开始找)
        System.out.println(index);

    }
    public static void main5(String[] args) {
        String s = "hello";
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            System.out.println(ch);
        }
/*        char ch = s.charAt(0);//查找
        System.out.println(ch);*/
        /*int[] array = {1,2,3,4,5};
        System.out.println(array.length);*/
    }
    public static void main4(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("abcdef");
        //比较字符串大小
        System.out.println(s1.compareTo(s2));//s1和s2进行比较
        // 1.根据对应字符比较
        // 2.不care字符串长短
        // 3.如果对应字符无法比较出来大小 此时 就看长度

        System.out.println(s1.compareToIgnoreCase(s2));//不区分大小写比较
    }
    public static void main3(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = s1;

        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println("==================");
        System.out.println(s1 == s2);
        System.out.println(s1 == s3);
        System.out.println(s2 == s3);
        System.out.println("==================");
        System.out.println(s1.equals(s2));
        System.out.println(s1.equals(s3));
        System.out.println(s2.equals(s3));
    }
    public static void main1(String[] args) {
        String str = "hello";
        String str2 = new String("world");
        char[] value = {'a','b','c'};
        String str3 = new String(value);

        System.out.println(str);
        System.out.println(str2);
        System.out.println(str3);
    }
}
